home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
F1 Licenseware
/
F1 Licenseware - Volume 1.iso
/
disks
/
089a.dms
/
089a.adf
/
example.lha
/
Life.AMOS
/
Life.amosSourceCode
Wrap
AMOS Source Code
|
1992-02-26
|
7KB
|
248 lines
' *********************************************
' * AmigaLife - by Mike Richmond 1994 *
' * Based on a "game" invented by John Conway *
' * Adapted from a listing in the book *
' * "The Joy of Computers" (Not sex) *
' * by Peter Laurie, 1983(!) *
' *********************************************
'
' Version 1.00
'
'
' "Life" is not a game, as such, in that it plays itself.
' It is a computerised study of artificial intelligence, and
' concerns a group of single-celled creatures (represented by an O
' The "game" is played on a board the size of the screen (40x24
' characters). Change the values of W and H to make the screen
' larger or smaller (in this case, only smaller). Each square has
' 2 possible states - alive or dead. Every "turn" the computer
' works out which squares are alive or dead using the following
' rules... (Neighbours being the eight cells surrounding the
' cell in question, as opposed to a popular Australian Soap Opera)
'
' A dead cell becomes alive if it has three live neighbours (the
' cells have 3 sexes, not 2)
'
' A cell with four or more live neighbours suffocates (Ha ha ha!)
'
' A cell with no live neighbours (or only 1), dies of exposure and
' loneliness (Awwww!)
'
' All you have to do is set up the lines of cells by inputting them
' at the prompt. A space is a dead cell and any other character is a
' live cell.
'
' Examples : ***** : This one gives you a 'blinker' (after a couple
' of generations it repeats a pattern forever)
'
' * : I could swear this one makes faces at me!!!
' *
' | *
' \|/ *
' V ...
' As far down as it will go
'
' **** * *
' * * ****
'
' You can have really big starting thingies if you can be bothered to
' type them in.
'
' Once you have pressed return on a blank line, the game kicks in. It
' draws the cells on the screen, then there is a slight pause while it
' works out births and deaths. then the screen redraws. You can leave
' it running for hours! Sometimes the game gets caught in a perpetual
' loop, and sometimes there can seem to be a form of intelligence behind
' the "random" patterns. Sometimes they all die and you are left with
' a blank screen! If this happens, you have to hold down the mouse button
' or use CTRL-C to quit.
'
' Oh, and hold down the left mouse button to quit the program
'
'
Set Buffer 16
' Increase the variable buffer as a lot of data is required
'
Gosub SETUP : Rem Set up the screen etc.
'
W=40 : H=24 : Rem Screen(W)IDTH and(H)EIGHT
'
Add W,-1 : Add H,-1
' Don't let graphics overflow the screen and make it scroll
'
Dim A(W+2,H+2),B(W+2,H+2)
' 2 arrays to hold the current gameboard and the old one
'
'
Print "Input Lines of cells. Hit Return alone to finish"
L=1
' L holds the number of lines inputted so far
'
INPLINES:
Input A$ : Inc L
' Take the inout and increase L
'
If A$="" Then Goto SHIFTPATTERN
' When the user has finished skip out of this bit
'
If ML<Len(A$)
ML=Len(A$)
End If
' Get longest line
'
If Len(A$)>W
Print "Too long!"
Goto INPLINES
End If
' Don't let the user input a line that is too long
'
If L>H
Goto SHIFTPATTERN
End If
' If there are enough lines, we can get going
'
For K=1 To Len(A$)
C$=Mid$(A$,K,1)
If C$<>" "
A(K,L)=1
End If
Next K
' Sort out the data for the line. A space is a gap, anything else is a
' living cell
'
Goto INPLINES
' And loop
'
SHIFTPATTERN:
SW=Int((W-ML-1)/2)
SH=Int(H-L-1)/2
For K=1 To ML
For J=1 To L
B(K+SW,J+SH)=A(K,J)
Next J
Next K
' This little For.. Next loop centres the longest line so that the screen
' display is also central.
'
Curs Off
' Get rid of the input cursor
'
Ink 0 : Bar 0,0 To 320,100 : Ink 1
Home : Centre "��� AmigaLife v1.00 ���"
' Clear INPUT text and replace it with a message.
'
Gosub DISPLAYARRAYB
' Display the array, today, Wha-hey! No way!
'
Repeat
' Do a generation from b to a
'
P0P=0
For K=1 To H
For J=1 To W
N=0 : C=B(J,K) : Rem Zero neighbour count, save cell value
N=B(J-1,K-1)+B(J,K-1)+B(J+1,K-1)+B(J-1,K)+B(J+1,K)+B(J-1,K+1)+B(J,K+1)+B(J+1,K+1)
' Count up neighbours
Gosub _DECISION
A(J,K)=NXT : Inc P0P : Rem put next generation into A
Next J
Next K
'
If P0P=0 Then Stop
'
Gosub DISPLAYARRAYA
'
' Now put generation into b
'
P0P=0
For K=1 To H
For J=1 To W
N=0 : C=B(J,K) : Rem Zero neighbour count, save cell value
N=A(J-1,K-1)+A(J,K-1)+A(J+1,K-1)+A(J-1,K)+A(J+1,K)+A(J-1,K+1)+A(J,K+1)+A(J+1,K+1)
' Count up neighbours
Gosub _DECISION
B(J,K)=NXT : Inc P0P : Rem put next generation into b
Next J
Next K
'
If P0P=0 Then Stop
'
Gosub DISPLAYARRAYB
'
Until Mouse Key<>0
Cls : Cdown : Cdown : Cdown : Cdown : Cdown
Centre "�� AmigaLife v1.00 ���"
Cdown : Cdown : Cdown : Cdown
Centre "Another great program from..."
Cdown : Cdown : Cdown : Cdown
Centre "RipperSoft"
Cdown : Cdown : Cdown : Cdown
Centre "Press Mouse button to return to editor"
Wait 50
Repeat
Until Mouse Key<>1
Proc CHUCKRAINBOW
Fade 2
Edit
'
' What's wrong with subroutines? Nobody uses them anymore! It saves you
' from having to define every variable as global at the start of the
' program. OK... OK... It's based on 1983 code. That's why it uses Goto
' and Gosub etc.
'
' SORRY! It took long enough removing the line numbers :-)
'
DISPLAYARRAYA:
Home : Cdown : Cdown
' Home cursor, using highly technical cursor moving technique
'
For K=1 To H
For J=1 To W
If A(J,K)=1 Then Print "O"; Else Print " ";
Next J
Print
Next K
' You can change the O to whatever you want. For example, *, %, @, # all
' look quite good. Who needs AGA when you've got the letter O?
' Don't forget to chnage it in the other display subroutine, though (unless
' you want to animate the cells! There's an idea!!
'
Return
'
DISPLAYARRAYB:
Home : Cdown : Cdown
For K=1 To H
For J=1 To W
If B(J,K)=1 Then Print "O"; Else Print " ";
Next J
Print
Next K
Return
'
_DECISION:
If N<2 or N>3 Then NXT=0 : Return
' Death by loneliness or overcrowding
If C=0 and N=3 Then NXT=1 : Return
' Birth
NXT=C : Rem No change
Return
'
SETUP:
Screen Open 0,320,256,2,Lowres
Flash Off : Wait Vbl
Palette $0,$FFF
Hide On : Wait Vbl
Set Rainbow 0,0,300,"","","(20,1,1)"
Rainbow 0,56,50,255
Text 10,220,"Adapted for AMOS by Mike Richmond"
Text 10,235,"Hold down left mouse button to quit"
'
'A rainbow jazzes up the 2 colour screen a little!
'
Return
Procedure CHUCKRAINBOW
For X=255 To 0 Step -2
Rainbow 0,56,40,X
Wait 1
Next
End Proc